package com.lft.graph03.shortest_path_graph01_dijkstra;

/**
 * 图——测试
 */
public class GraphDemo {
	public static void main(String[] args) {
		GraphAdjacencyMatrix graphMatrix = new GraphAdjacencyMatrix(6, String.class);
		graphMatrix.insertVertex("V1");
		graphMatrix.insertVertex("V2");
		graphMatrix.insertVertex("V3");
		graphMatrix.insertVertex("V4");
		graphMatrix.insertVertex("V5");
		graphMatrix.insertVertex("V6");
		
		graphMatrix.insertEdge(0, 2, 10);
		graphMatrix.insertEdge(0, 4, 30);
		graphMatrix.insertEdge(0, 5, 100);
		graphMatrix.insertEdge(1, 2, 5);
		graphMatrix.insertEdge(2, 3, 50);
		graphMatrix.insertEdge(3, 5, 10);
		graphMatrix.insertEdge(3, 4, 20);
		graphMatrix.insertEdge(4, 5, 60);
		
		System.out.println("打印邻接矩阵——图");
		graphMatrix.displayGraph();
		
		// System.out.println("删除邻接矩阵边");
		// graphMatrix.deleteEdge(0, 1);
		// graphMatrix.displayGraph();
		
		System.out.println("遍历邻接矩阵1深度优先搜索——栈");
		System.out.println(graphMatrix.depthFirstSearchByStack(0));
		
		// System.out.println("删除邻接矩阵顶点");
		// graphMatrix.deleteVertex("A");
		// graphMatrix.displayGraph();
		System.out.println("遍历邻接矩阵1深度优先搜索——递归");
		System.out.println(graphMatrix.depthFirstSearchByRecursion(0));
		
		System.out.println("遍历邻接矩阵2广度优先搜索");
		System.out.println(graphMatrix.breadFirstSearchByQueue(0));
		
		graphMatrix.dijkstra(0);
		
		System.out.println("打印最短路径：");
		graphMatrix.displayShortestPath(0);
		
		System.out.println("===============================================");
		
		GraphAdjacencyList graphList = new GraphAdjacencyList(8);
		graphList.insertVertex("V1");
		graphList.insertVertex("V2");
		graphList.insertVertex("V3");
		graphList.insertVertex("V4");
		graphList.insertVertex("V5");
		graphList.insertVertex("V6");
		
		graphList.insertEdge(0, 2, 10);
		graphList.insertEdge(0, 4, 30);
		graphList.insertEdge(0, 5, 100);
		graphList.insertEdge(1, 2, 5);
		graphList.insertEdge(2, 3, 50);
		graphList.insertEdge(3, 4, 20);
		graphList.insertEdge(3, 5, 10);
		graphList.insertEdge(4, 5, 60);
		
		System.out.println("打印邻接表——图");
		graphList.displayGraph();
		
		// System.out.println("删除邻接表边");
		// graphList.deleteEdge(0, 1);
		// graphList.displayGraph();
		
		System.out.println("遍历邻接表1深度优先搜索——栈");
		System.out.println(graphList.depthFirstSearchByStack(0));
		
		// System.out.println("删除邻接表顶点");
		// graphList.deleteVertex("A");
		// graphList.displayGraph();
		
		System.out.println("遍历邻接表1深度优先搜索——递归");
		System.out.println(graphList.depthFirstSearchByStack(0));
		
		System.out.println("遍历邻接矩阵2广度优先搜索");
		System.out.println(graphList.breadFirstSearchByQueue(0));
		graphList.displayShortestPath(0);
	}
}

